﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class PictureService : IPictureService
    {
        private IPictureRepository _pictureRepository;

        #region IPictureService Members

        /// <summary>
        /// create new picture
        /// </summary>
        /// <param name="theNewPicture">the new picture instance</param>
        /// <returns>the new picture's ID</returns>
        public int CreateNewPicture(Data.Entity.Picture theNewPicture)
        {
            if (theNewPicture == null)
            {
                return 0;
            }

            if (_pictureRepository == null)
            {
                _pictureRepository = new PictureRepository();
            }

            return _pictureRepository.CreateNewPicture(theNewPicture);
        }

        public IList<Data.Entity.Picture> GetPicturesByProduct(int productID)
        {
            if (productID <= 0)
            {
                return null;
            }

            if (_pictureRepository == null)
            {
                _pictureRepository = new PictureRepository();
            }

            return _pictureRepository.GetPicturesByProduct(productID);
        }

        public int UpdatePicture(Data.Entity.Picture thePicture)
        {
            if (thePicture == null || thePicture.PictureID <= 0)
            {
                return 0;
            }

            if (_pictureRepository == null || thePicture.PictureID <= 0)
            {
                _pictureRepository = new PictureRepository();
            }

            return _pictureRepository.UpdatePicture(thePicture);
        }

        public Data.Entity.Picture GetPicture(int id)
        {
            if (id <= 0)
            {
                return null;
            }

            if (_pictureRepository == null)
            {
                _pictureRepository = new PictureRepository();
            }

            return _pictureRepository.GetPicture(id);
        }

		public IList<Data.Entity.Picture> GetPicturesByProduct_WithoutBinary(int productid)
		{
			if(productid <= 0)
			{
				return null;
			}

			if(_pictureRepository == null)
			{
				_pictureRepository = new PictureRepository();
			}

			return _pictureRepository.GetPicturesByProduct_WithoutBinary(productid);
		}

		public Data.Entity.Picture GetTheProductDefaultPicture(int theProductID)
		{
			if(theProductID <= 0)
			{
				return null;
			}

			if(_pictureRepository == null)
			{
				_pictureRepository = new PictureRepository();
			}

			return _pictureRepository.GetTheProductDefaultPicture(theProductID);
		}

		#endregion
	}
}
